import React,{Suspense} from 'react'
import routes from "./Router_config"
import {BrowserRouter,Route,Routes,Navigate} from "react-router-dom"
type Props = {}

const RouterView = (props: Props) => {
    const renderroutes=(arr:any)=>{
    return arr.map((item:any,index:number)=>{
      return <Route path={item.path} key={index} element={
        item.element?<item.element/>:<Navigate to={item.to as string}/>
      }>
        {
            item.children&&renderroutes(item.children)
        }
      </Route>
    })
    }
  return (
    <Suspense>
        <BrowserRouter>
        <Routes>
            {
           renderroutes(routes)
            }
        </Routes>
        </BrowserRouter>
    </Suspense>
  )
}

export default RouterView